<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//定时器相关
class Exper_award_model extends CI_Model{
    function __construct() {
        parent::__construct();
        $this->table = 'plat';
        $this->plat_info = 'plat_info';
        $this->plat_log = 'plat_log';
        $this->plat_rule = 'plat_rule';
        $this->plat_award_list = 'plat_award_list';
        $this->plat_ab_cpa = 'plat_ab_cpa';
        $this->plat_ac_cpa = 'plat_ac_cpa';
        $this->plat_interface = 'plat_interface';
        $this->plat_invest_list = 'plat_invest_list';
        $this->users_table = 'users';
    }
    
    function get_plat($where){
        $this->db->select('id,name_ch,name_en,plat_type,access_key,is_show,pay_amount');
        $this->db->from($this->table);
        $this->db->where($where);
        $query = $this->db->get();
        return $query->row_array(); 
    }
    
    //获取平台预付款
    function get_plat_payamount($where){
        $this->db->select($this->table.'.pay_amount');
        $this->db->from($this->table);
        $this->db->where($where);
        $query = $this->db->get();
        $result = $query->row_array();
        return $result['pay_amount']; 
    }
    
    function get_info($where){
        $this->db->select($this->table.'.*,'.$this->plat_info.'.*');
        $this->db->from($this->table);
        $this->db->join($this->plat_info, $this->plat_info.'.plat_id = '.$this->table.'.id', 'left');
        $this->db->where($where);
        $this->db->order_by("plat.create_time", "desc");
        $query = $this->db->get();
        return $query->row_array(); 
    }
    
    function get_award_list($where){
        $this->db->select($this->plat_award_list.'.*');
        $this->db->from($this->plat_award_list);
        $this->db->where($where);
        $this->db->order_by("create_time", "asc");
        $query = $this->db->get();
        return $query->row_array(); 
    }
    
    function check_ac_cpa($where){
        $this->db->select($this->plat_ac_cpa.'.*');
        $this->db->from($this->plat_ac_cpa);
        $this->db->where($where);
        $query = $this->db->get();
        return $query->row_array(); 
    }
    
    function check_ab_cpa($where){
        $this->db->select($this->plat_ab_cpa.'.*');
        $this->db->from($this->plat_ab_cpa);
        $this->db->where($where);
        $query = $this->db->get();
        return $query->row_array(); 
    }
    
    function get_rules($where){
        $this->db->select("*");
        $this->db->from($this->plat_rule);
        $this->db->where($where);
        $this->db->order_by('step','asc');
        return $this->db->get()->result_array();
    }
    
    function get_interface($where){
        $this->db->select($this->plat_interface.'.*');
        $this->db->from($this->plat_interface);
        $this->db->where($where);
        $query = $this->db->get();
        return $query->row_array(); 
    }
    
    function get_plat_invest($where){
        $this->db->select($this->plat_invest_list.'.*');
        $this->db->from($this->plat_invest_list);
        $this->db->where($where);
        $query = $this->db->get();
        return $query->row_array(); 
    }
    
    function insert_ab_cpa($data){
        $this->db->insert($this->plat_ab_cpa, $data);
        if($this->db->affected_rows()){
            return $this->db->insert_id();
        }else{
            return 0;
        }
    }
    
    function update_plat($data,$id){
        return $this->db->where('id',$id)->update($this->table, $data);
    }
    function insert_ac_cpa($data){
        $this->db->insert($this->plat_ac_cpa, $data);
        if($this->db->affected_rows()){
            return $this->db->insert_id();
        }else{
            return 0;
        }
    }
    
    function insert_plat_invest_list($data){
        $this->db->insert($this->plat_invest_list, $data);
        if($this->db->affected_rows()){
            return $this->db->insert_id();
        }else{
            return 0;
        }
    }
    
    function insert_plat_log($data){
        $this->db->insert($this->plat_log, $data);
        if($this->db->affected_rows()){
            return $this->db->insert_id();
        }else{
            return 0;
        }
    }
    
    function update_ab_cpa($data,$id){
        return $this->db->where('id',$id)->update($this->plat_ab_cpa, $data);
    }
    
    function update_ac_cpa($data,$id){
        return $this->db->where('id',$id)->update($this->plat_ac_cpa, $data);
    }
    
    
    function get_ab_cpa_query(){
        
    }
    
    function get_ac_cpa_query(){
        $sql = "select tan_plat_ac_cpa.*";
        $handle = $this->db->query($sql);
        return $handle->result_array();
    }
    
    
}
